package com.ja.openchat.ui.found;

import androidx.recyclerview.widget.DiffUtil;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.zy.openchat.core.model.circle.BlogInfo;
import com.zy.openchat.core.model.circle.BlogReplyInfo;

import java.util.List;

public class BlogAvatarDiffCallBack extends DiffUtil.Callback{

    private List<MultiItemEntity> mOldDatas, mNewDatas;

    public BlogAvatarDiffCallBack(List<MultiItemEntity> oldDatas, List<MultiItemEntity> newDatas) {
        this.mOldDatas = oldDatas;
        this.mNewDatas = newDatas;
    }


    @Override
    public int getOldListSize() {
        return mOldDatas != null ? mOldDatas.size() : 0;
    }

    // 新数据集 size
    @Override
    public int getNewListSize() {
        return mNewDatas != null ? mNewDatas.size() : 0;
    }


    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        MultiItemEntity oldEn = mOldDatas.get(oldItemPosition);
        MultiItemEntity newEn = mNewDatas.get(newItemPosition);
        if(oldEn instanceof BlogInfo&&newEn instanceof BlogInfo){
            return ((BlogInfo)oldEn).isMessageEqual(((BlogInfo)newEn));
        }else if(oldEn instanceof BlogReplyInfo &&newEn instanceof BlogReplyInfo){
            return ((BlogReplyInfo)oldEn).isMessageEqual(((BlogReplyInfo)newEn));
        }else{
            return false;
        }

    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        MultiItemEntity oldEn = mOldDatas.get(oldItemPosition);
        MultiItemEntity newEn = mNewDatas.get(newItemPosition);
        if(oldEn instanceof BlogInfo&&newEn instanceof BlogInfo){
            return ((BlogInfo)oldEn).isAvaterDownloadEqual(((BlogInfo)newEn));
        }else if(oldEn instanceof BlogReplyInfo &&newEn instanceof BlogReplyInfo){
            return ((BlogReplyInfo)oldEn).isAvaterDownloadEqual(((BlogReplyInfo)newEn));
        }else{
            return false;
        }
    }
}
